package com.zll.exam;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Test1 {
    static HashSet<Point> set = null;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int m = scan.nextInt();
            int n = scan.nextInt();
            set = new HashSet<>();
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    int value = scan.nextInt();
                    if(value==1){
                        add(new Point(i,j), m, n);
                    }
                }
            }
            System.out.println(set.size());
        }
    }
    public static void add(Point point, int m, int n){
        set.add(point);
        if(point.x+1<m) set.add(new Point(point.x+1,point.y));
        if(point.x-1>=0) set.add(new Point(point.x-1,point.y));
        if(point.y+1<n) set.add(new Point(point.x,point.y+1));
        if(point.y-1>=0) set.add(new Point(point.x,point.y-1));
    }
}

class Point{
    int x;
    int y;

    public Point(int x,int y){
        this.x = x;
        this.y = y;
    }

    @Override
    public int hashCode() {
        return this.x*100+this.y;
    }

    @Override
    public boolean equals(Object obj) {
        Point p = (Point) obj;
        return p.x == this.x && p.y == this.y;
    }

}
